import request from '@/utils/request'

/* *
 * 获取用户数据列表
 */
export const getUserList = params =>
  request({
    url: 'users',
    params
  })

/* *
 * 修改用户状态
 */
export const changeUserState = (uld, type) =>
  request({
    method: 'PUT',
    url: `users/${uld}/state/${type}`
  })

/* *
 * 新增用户
 */
export const addUser = data =>
  request({
    method: 'POST',
    url: 'users',
    data
  })

/* *
 * 根据 ID 查询用户信息
 */
export const getUserInfoById = id => request(`users/${id}`)

/* *
 * 编辑用户提交
 */
export const editUserInfo = (id, data) =>
  request({
    method: 'PUT',
    url: `users/${id}`,
    data
  })

/* *
 * 根据 ID 删除用户
 */
export const deleteUserById = id =>
  request({
    method: 'DELETE',
    url: `users/${id}`
  })

/* *
 * 分配用户角色
 */
export const resetUserRoles = (userId, roleId) =>
  request({
    method: 'PUT',
    url: `users/${userId}/role`,
    data: {
      rid: roleId
    }
  })
